package com.kaifamiao.month05.day09;


import java.time.LocalTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo02 {

    public static void main(String[] args) throws InterruptedException {
//        ExecutorService es = Executors.newCachedThreadPool();
        ExecutorService es = Executors.newFixedThreadPool(5); // 有5个线程，不会增加也不会


        for (int i = 0; i < 10; i++) {
            int num = i;
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);
                        System.out.println(Thread.currentThread().getName() + " , 执行时间：" + LocalTime.now() + " , 编号：" + num);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
//        Thread.sleep(63000);
//        es.execute(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println(Thread.currentThread().getName() + " , 执行时间：" + LocalTime.now());
//            }
//        });
    }
}
